package shengchanxiaofei;

import java.util.Random;

public class Producer extends Thread {
	private Repository<BaoZi> zhenglong;

    public Producer(Repository<BaoZi> zhenglong){
    	this.zhenglong=zhenglong;
    }
    
    public void run(){
    	String[] names={"菜包","肉包","豆沙包","灌汤包"};
    	int c=0;
    	Random rd=new Random();
    	while(true){
    		c++;   		
    		BaoZi bz=new BaoZi(c,names[rd.nextInt(4)]);
    		zhenglong.save(bz);
    		System.out.println("生产了"+c+"号"+bz.getName());
    		try {
    			Thread.sleep((int)(Math.random()*1000));
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    }

}
